package com.ruoyi.project.system.device.pdf;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;

import java.io.IOException;

public class InitPdfTable {


    public static <T> Paragraph getFirstTable(String title, String prefixDescribe, String suffixDescribe) throws DocumentException, IOException {

        // 1.创建一个表格
        PdfPTable table = new PdfPTable(2);// 列数
        setRowData(table,1,2,"REQUEST INFORMATION",13,Element.ALIGN_LEFT);

        setRowData(table,1,1,"Submission Date");
        setRowData(table,1,1,"2024-07-12");
        setRowData(table,1,1,"Request Number");
        setRowData(table,1,1,"TEC XXX/XX");
        setRowData(table,1,1,"Request Name");
        setRowData(table,1,1,"Outgassing test of PEEK");
        setRowData(table,1,1,"Project Account");
        setRowData(table,1,1,"XXXX");
        setRowData(table,1,1,"Confidentiality");
        setRowData(table,1,1,"Internal");
        setRowData(table,1,1,"Deadline");
        setRowData(table,1,1,"XXXX");

        // 4.返回段落
        return ReportFormUtil.createParagraph(table, title, prefixDescribe, suffixDescribe);
    }

    public static <T> Paragraph getSecondTable(String title, String prefixDescribe, String suffixDescribe) throws DocumentException, IOException {

        // 1.创建一个表格
        PdfPTable table = new PdfPTable(5);// 列数
        setRowData(table,1,5,"REQUEST DESCRIPTION\n" +
                "Outgassing test of PEEK",13,Element.ALIGN_LEFT);

        setRowData(table,1,1,"Sample #");
        setRowData(table,1,1,"Designation");
        setRowData(table,1,1,"Request Number");
        setRowData(table,1,1,"Nature");
        setRowData(table,1,1,"Tests");
        setRowData(table,1,1,"Assigned to");
        setRowData(table,1,1,"001");
        setRowData(table,1,1,"XXXX");
        setRowData(table,1,1,"PEEK");
        setRowData(table,1,1,"Solid");
        setRowData(table,1,1,"outgas");
        setRowData(table,1,1,"XXX");

        // 4.返回段落
        return ReportFormUtil.createParagraph(table, title, prefixDescribe, suffixDescribe);
    }


    public static <T> Paragraph getThirdTable(String title, String prefixDescribe, String suffixDescribe) throws DocumentException, IOException {

        // 1.创建一个表格
        PdfPTable table = new PdfPTable(4);// 列数


        setRowData(table,1,4,"SAMPLES PHOTO",13,Element.ALIGN_LEFT);
        setRowDataImage(table,1,4,"D:\\exportPdf\\234.png",13,Element.ALIGN_CENTER);

        setRowData(table,1,1,"Sample Preparation");
        setRowData(table,1,3,"");

        setRowData(table,23,1,"Instrument Parameters");

        setRowData(table,7,1,"Sample Chamber");
        setRowData(table,1,1,"Equipment Name");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Running Time");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Thermostatic Time (Setting)");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Vacuum (Setting)");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Start Temperature (Setting)");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"End Temperature (Setting)");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Heating Rate (Setting)");
        setRowData(table,1,1,"");

        setRowData(table,5,1,"Cold Trap");
        setRowData(table,1,1,"Cooling Temperature");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"CT Duration");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Heating Temperature ");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"HT Duration");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Trapping Time");
        setRowData(table,1,1,"");

        setRowData(table,2,1,"Pipe");
        setRowData(table,1,1,"Temperature 1 (Setting)");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Temperature 2 (Setting)");
        setRowData(table,1,1,"");

        setRowData(table,3,1,"Gas Chromatography");
        setRowData(table,1,1,"Column Type");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Column Flow Rate");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Heating Program");
        setRowData(table,1,1,"");

        setRowData(table,6,1,"Mass Spectra");
        setRowData(table,1,1,"Ionization Mode");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Inlet Temperature");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Ion Source Temperature");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Scan Mode");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"Start Mass");
        setRowData(table,1,1,"");
        setRowData(table,1,1,"End Mass");
        setRowData(table,1,1,"");


        // 4.返回段落
        return ReportFormUtil.createParagraph(table, title, prefixDescribe, suffixDescribe);
    }



    public static <T> Paragraph getFourTable(String title, String prefixDescribe, String suffixDescribe) throws DocumentException, IOException {

        // 1.创建一个表格
        PdfPTable table = new PdfPTable(4);// 列数
        setRowData(table,1,4,"气相色谱分析条件");
        setRowData(table,1,2,"色谱柱");
        setRowData(table,1,2,"Elite-5MS 30M X 0.25mm X 0.25um");
        setRowData(table,1,2,"载气类型");
        setRowData(table,1,2,"氦气");
        setRowData(table,1,2,"色谱柱流量");
        setRowData(table,1,2,"1ml/min");
        setRowData(table,3,1,"柱温程序");
        setRowData(table,1,1,"温度");
        setRowData(table,1,1,"持续时间");
        setRowData(table,1,1,"速率");
        setRowData(table,1,1,"40°C");
        setRowData(table,1,1,"1min");
        setRowData(table,1,1,"10°C/min");
        setRowData(table,1,1,"280°C");
        setRowData(table,1,1,"15min");
        setRowData(table,1,1,"END");
        setRowData(table,1,4,"质谱分析条件");
        setRowData(table,1,2,"扫描范围");
        setRowData(table,1,2,"33-450amu");
        setRowData(table,1,2,"扫描时间");
        setRowData(table,1,2,"0.25s");
        setRowData(table,1,4,"带捕集阱顶空分析条件");
        setRowData(table,1,2,"加热温度");
        setRowData(table,1,2,"1202C /2009C");
        setRowData(table,1,2,"加热时间");
        setRowData(table,1,2,"45min");
        setRowData(table,1,2,"脱附温度");
        setRowData(table,1,2,"280C");


        // 4.返回段落
        return ReportFormUtil.createParagraph(table, title, prefixDescribe, suffixDescribe);
    }

    public static void setRowData(PdfPTable table,int setRowspan,int setColspan,String text) throws IOException, DocumentException {
        setRowData(table,setRowspan,setColspan,text,-1,Element.ALIGN_CENTER);
    }
    public static void setRowData(PdfPTable table,int setRowspan,int setColspan,String text,int disableBorderSide,int position) throws IOException, DocumentException {
        //定义数据的字体
        BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font textFont = new Font(baseFont, 10, Font.NORMAL);
        PdfPCell heandCell = new PdfPCell();
        heandCell.setRowspan(setRowspan);
        heandCell.setColspan(setColspan);
        heandCell.setMinimumHeight(30);
        heandCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        heandCell.setHorizontalAlignment(position);
        heandCell.setPhrase(new Phrase(text, textFont));
        if(disableBorderSide>0){
            heandCell.disableBorderSide(disableBorderSide);//隐藏边框
        }
        table.addCell(heandCell);
    }

    public static void setRowDataImage(PdfPTable table,int setRowspan,int setColspan,String imagePath,int disableBorderSide,int position) throws IOException, DocumentException {
        //定义数据的字体
        BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font textFont = new Font(baseFont, 10, Font.NORMAL);
        PdfPCell heandCell = new PdfPCell();
        heandCell.setRowspan(setRowspan);
        heandCell.setColspan(setColspan);
        heandCell.setMinimumHeight(30);
        heandCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        heandCell.setHorizontalAlignment(position);

        Image icon = Image.getInstance(imagePath);
        icon.scaleToFit(90f, 90f);
        Font font1 = new Font(BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 8, Font.BOLD, BaseColor.RED);
        Chunk textChunk = new Chunk("55.79%", font1);
        Chunk imageChunk = new Chunk(icon, 0, 0, true); // 图片作为一个Chunk

        heandCell.setPhrase(new Phrase(imageChunk));
        if(disableBorderSide>0){
            heandCell.disableBorderSide(disableBorderSide);//隐藏边框
        }
        table.addCell(heandCell);
    }


}
